package com.ruoyi.web.controller.invoice;

import com.ruoyi.dto.NameDto;
import com.ruoyi.dto.NsrshbDto;
import com.ruoyi.third.base.InvoiceApiResult;
import com.ruoyi.third.entity.request.CommodityAdd;
import com.ruoyi.third.entity.request.CommodityDel;
import com.ruoyi.third.service.BmxxService;
import com.ruoyi.third.service.SpbmJbxxService;
import com.ruoyi.third.service.ThirdApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;


@Api(tags = "商品")
@RestController
@AllArgsConstructor
@RequestMapping("invoice/commodity")
public class CommodityController {

    private final ThirdApiService thirdApiService;
    private final BmxxService bmxxService;
    private final SpbmJbxxService spbmJbxxService;


    @ApiOperation(value = "智能赋码", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "商品名称", dataTypeClass = String.class)
    })
    @PostMapping("intelligCoding")
    public InvoiceApiResult intelligCoding(@RequestBody @Validated NameDto nameDto) {
        return thirdApiService.intelligCoding(nameDto.getName());
    }

    @ApiOperation(value = "智能赋码51", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "商品名称", dataTypeClass = String.class)
    })
    @PostMapping("seachIntelligenceCoding")
    public InvoiceApiResult seachIntelligenceCoding(@RequestBody @Validated NameDto nameDto) {
        return thirdApiService.seachIntelligenceCoding(nameDto.getName());
    }


    @ApiOperation(value = "商品编码查询", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nsrsbh", value = "纳税人识别号", dataTypeClass = String.class)
    })
    @PostMapping("commoditySearch")
    public InvoiceApiResult commoditySearch(@RequestBody @Validated NsrshbDto nsrshbDto) {
        return thirdApiService.commoditySearch(nsrshbDto.getNsrsbh());
    }

    @ApiOperation(value = "删除商品编码", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CommodityDel", value = "CommodityDel", dataTypeClass = CommodityDel.class)
    })
    @PostMapping("commodityDel")
    public InvoiceApiResult commodityDel(@RequestBody @Validated CommodityDel commodityDel) {
        return thirdApiService.commodityDel(commodityDel);
    }

    @ApiOperation(value = "新增商品编码", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CommodityAdd", value = "CommodityAdd", dataTypeClass = CommodityAdd.class)
    })
    @PostMapping("addInvoiceSp")
    public InvoiceApiResult addInvoiceSp(@RequestBody @Validated CommodityAdd commodityAdd) {
        return thirdApiService.addInvoiceSp(commodityAdd);
    }

    @ApiOperation(value = "SPBM列表", httpMethod = "POST")
    @ApiImplicitParams({
    })
    @PostMapping("getBmxxList")
    public InvoiceApiResult getBmxxList() {
        return InvoiceApiResult.success(bmxxService.getList());
    }

    @ApiOperation(value = "SPBM列表-根据名称", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "商品名称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "page", value = "page", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "rows", value = "rows", dataTypeClass = Integer.class)
    })
    @GetMapping("getBmxxListBySpmc")
    public InvoiceApiResult getBmxxListBySpmc(@RequestParam String name, @RequestParam @Min(1) Integer page, @RequestParam @Min(1) Integer rows) {
        return InvoiceApiResult.success(bmxxService.getByPage(name,page,rows));
    }

    @ApiOperation(value = "SPBM列表CSV", httpMethod = "POST")
    @ApiImplicitParams({
    })
    @PostMapping("getBmxxListCsv")
    public InvoiceApiResult getBmxxListCsv() {
        return InvoiceApiResult.success(spbmJbxxService.getList());
    }


    @ApiOperation(value = "SPBM列表-根据名称CSV", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "商品名称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "page", value = "page", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "rows", value = "rows", dataTypeClass = Integer.class)
    })
    @Validated
    @GetMapping("getBmxxListBySpmcCsv")
    public InvoiceApiResult getBmxxListBySpmcCsv(@RequestParam String name, @RequestParam @Min(1) Integer page, @RequestParam @Min(1) Integer rows) {
        return InvoiceApiResult.success(spbmJbxxService.getByPage(name,page,rows));
    }


}
